package com.xingkeduo.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BeanUtils {
	public static String buildStartAndEndWithZero(String str) {
		if (StringUtils.isBlank(str)) {
			str = "0";
		}
		str = str.replaceAll(",,", ",");
		if(!str.startsWith("0") 
				&& !str.startsWith(",")) {
			str = "," + str;
		}
		if(!str.endsWith("0") 
				&& !str.endsWith(",")) {
			str = str+",";
		}
		if(str.startsWith(",0,")) {
			str = str.substring(1, str.length());
		}
		if(str.endsWith(",0,")) {
			str = str.substring(0, str.length()-1);
		}
		if(str.startsWith(",")) {
			str = "0"+str;
		}
		if(str.endsWith(",")) {
			str = str+"0";
		}
		return str;
	}
	
	public static String removerepeatedchar(String str) {
		if (StringUtils.isBlank(str)) {
			return  "0";
		}
        String[] newStrArray = str.split(",");
        Map<String, String> map = new HashMap<String, String>();
        for (String newStr : newStrArray) {
            map.put(newStr, newStr);
        }
        Collection<String> valueCollection = map.values();
        List<String> valueList = new ArrayList<String>(valueCollection);
        return StringUtils.join(valueList, ",");
    }
}
